package com.clp.util.hutool.core.map;

import java.util.HashMap;
import java.util.Map;

public class CaseInsensitiveMap<K, V> extends CustomKeyMap<K, V> {

    public CaseInsensitiveMap(Map<? extends K, ? extends V> m) {
        this(DEFAULT_LOAD_FACTOR, m);
    }

    public CaseInsensitiveMap(float loadFactor, Map<? extends K, ? extends V> m ){
        this(m.size(), loadFactor);
        this.putAll(m);
    }

    public CaseInsensitiveMap(int initialCapacity, float loadFactor) {
        super(new HashMap<>(initialCapacity, loadFactor));
    }

    /**
     * 将Key转为小写
     *
     * @param key KEY
     * @return 小写KEY
     */
    @Override
    protected Object customKey(Object key) {
        if (key instanceof CharSequence) {
            key = key.toString().toLowerCase();
        }
        return key;
    }
}
